﻿using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;

namespace DDDDemoABP1.Payments;

public class Account: FullAuditedAggregateRoot<Guid>
{
    public Guid UserId { get; protected set; }
    public string AccountNo { get; protected set; }
    public decimal Balance { get; protected set; }

    protected Account()
    {

    }

    public Account(Guid userId, string accountNo, decimal balance = 0m)
    {
        Id = userId;
        UserId = userId;
        AccountNo = accountNo;
        Balance = balance;
    }

    /// <summary>
    /// 转入操作
    /// <summary>
    public void TransferIn(decimal amount)
    {
        Balance += amount;
    }

    /// <summary>
    /// 转出操作
    /// <summary>
    public void TransferOut(decimal amount)
    {
        if (Balance < amount)
        {
            throw new UserFriendlyException("余额不足", "NoMoney");
        }
        Balance -= amount;
    }
}
